<script setup>
import { ref, toRaw } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import Type from '@components/search/type'
import Search from '@components/search/index'
import PageWrapper from '@components/PageWrapper.vue'
import { common, service } from '@utils'
import { SERVE_URL,imgSERVEURL } from '@utils/config'

const searchs = ref([
    {
        type: Type.INPUT,
        key: 'nickName',
        width: 5,
        placeholder: '用户名称',
        likes:true
    },
    {
        type: Type.INPUT,
        key: 'linkPhone',
        width: 5,
        placeholder: '联系方式',
        likes:true
    },
    {
        type: Type.INPUT,
        key: 'linkEmail',
        width: 5,
        placeholder: '联系邮箱',
        likes:true
    },
    {
        width: 6,
        type: Type.SEARCH_BUTTON
    }
])

const pageRef = ref()
const tableRef = ref()

let queryForm = {}

const onSearch = (param) => {
    queryForm = param
    pageRef.value.refresh()
}

const getData = async ({ pageNum, pageSize }, cb) => {
    const res = await service.bfqz.suggestions(pageNum, pageSize, queryForm)
    cb(res)
    setTimeout(() => {
        tableRef.value.scrollTo(0, 0)
    }, 0)
}

</script>
    <template>
    <section class="main-white">
        <search :items="searchs" @filter="onSearch" />
        <page-wrapper @get-data="getData" ref="pageRef">
            <template v-slot:default="props">
                <vxe-table ref="tableRef" :loading="props.loading" :data="props.tableData.records" :max-height="common.tableHeight(true, 1)"
                    highlight-hover-row round stripe border>
                    <vxe-column type="seq" width="60"></vxe-column>
                    <vxe-column field="createTime" title="创建时间" width="160" />
                    <vxe-column field="nickName" title="用户名称" />
                    <vxe-column field="content" title="建议内容" />
                    <vxe-column title="建议图片">
                        <template #default="{ row }">
                            <section class="flex-align flex-wrap" v-if="row.images && row.images.length > 0">
                                <el-image v-for="(item, index) in row.images" :key="index" :src="imgSERVEURL + item"
                                    :preview-src-list="[imgSERVEURL + item]" class="marginX5 table-image" fit="contain"></el-image>
                            </section>
                        </template>
                    </vxe-column>
                    <vxe-column field="linkPhone" title="联系方式" />
                    <vxe-column field="linkEmail" title="联系邮箱" />
                </vxe-table>
            </template>
        </page-wrapper>
    </section>
</template>